<?php if (!defined('_VALID_MOS')) die('Direct Access to this location is not allowed.');
/**
 * JoomLeague 0.90 sef_ext file for Artio JoomSEF 2.0.x
 * 2007-07-31 by Robert Moss
 * www.joomleague.de  
 */
 
class sefext_com_joomleague extends sef_404

{
    function create($string, &$vars) {
        global $sefConfig, $database;
        
        extract($vars);
        
        // Load season name and league
        if (isset($p)) { 
            $query = "SELECT `league_id`	FROM `#__joomleague` WHERE `id` = $p";
            $database->setQuery($query);
            $league_id = $database->loadResult();
            
            $query = "SELECT `name`	FROM `#__joomleague_leagues` WHERE `id` = $league_id";
            $database->setQuery($query);
            $league_name = $database->loadResult();
                
            $query = "SELECT `season_id` FROM `#__joomleague`	WHERE `id` = $p";
            $database->setQuery($query);
            $season_id = $database->loadResult();
            
            $query = "SELECT `name`	FROM `#__joomleague_seasons` WHERE `id` = $season_id";
            $database->setQuery($query);
            $season_name = $database->loadResult();    
        }

        if (!empty($league_name)) { $title[] = $league_name; $title[] = $season_name; unset($vars['p']); }
        
        // Load function ($func)
        $func=strtolower($func);
        if ($lang=='en'){
        switch ($func)
            {
            case 'about': { $title[] = 'about'; break; }
            case 'showcurve': { $title[] = 'fevercharts'; break; }
            case 'dotips': { $title[] = 'prediction'; break; }        
            case 'savedtips': { $title[] = 'predicts_saved'; break; }
            case 'showtipranking': { $title[] = 'points'; break; }
            case 'showtipresults': { $title[] = 'predict_results'; break; }
            case 'showranking': 
            if ($type == "1") { $title[] = 'home_ranking'; break;}
            if ($type == "2") { $title[] = 'away_ranking'; break;}  
            else { $title[] = 'ranking'; break; }                                
            case 'showresultsrank': { $title[] = 'results_and_ranking'; break; }
            case 'showplan': { $title[] = 'matchplans'; break; }
            case 'showresults': { $title[] = 'results'; break; }  
            case 'shownextmatch': { $title[] = 'season_stats'; break; } 
            case 'editresults': { $title[] = 'edit_results'; break; } 
            case 'saveresults': { $title[] = 'save_results'; break; } 
            case 'showmatrix': { $title[] = 'crosstables'; break; } 
            case 'showreport': { $title[] = 'matchreports'; break; }                                         
            case 'showteaminfo': { $title[] = 'teams'; break; } 
            case 'showclubinfo': { $title[] = 'clubs'; break; } 
            case 'showplayers': { $title[] = 'teamplayers'; break; }  
            case 'showplayer': { $title[] = 'players'; break; }
            case 'showtiprules': { $title[] = 'prediction/rules'; break; }
            case 'showstats': { $title[] = 'stats'; break; } 
            case 'showuser': { $title[] = 'users'; break; }    
            case 'showplayground': { $title[] = 'playgrounds'; break; }
            case 'eventsstats': { $title[] = 'events'; break; }                              
            unset($vars['func']);              
            }
        }
        else
        switch ($func)
        {
            case 'about': { $title[] = 'about'; break; }
            case 'showcurve': { $title[] = 'fieberkurven'; break; }
            case 'dotips': { $title[] = 'tippabgabe'; break; }        
            case 'savedTips': { $title[] = 'tipps_gespeichert'; break; }
            case 'showtipranking': 
            if ($mode == "all") { $title[] = 'gesamtpunkte'; } 
            else { $title[] = 'spieltagspunkte'; }
            break;
            case 'showtipresults': { $title[] = 'tippuebersicht'; break; }
            case 'showranking': 
            if ($type == "1") { $title[] = 'heimtabelle'; break;}
            if ($type == "2") { $title[] = 'auswaertstabelle'; break;}  
            else { $title[] = 'tabelle'; break; }                                
            case 'showresultsrank': { $title[] = 'ergebnisse_und_tabelle'; break; }
            case 'showplan': { $title[] = 'spielplaene'; break; }
            case 'showresults': { $title[] = 'ergebnisse'; break; }  
            case 'shownextmatch': { $title[] = 'saisonstatistik'; break; } 
            case 'editresults': { $title[] = 'ergebnisse_bearbeiten'; break; } 
            case 'saveresults': { $title[] = 'ergebnisse_speichern'; break; } 
            case 'showmatrix': { $title[] = 'kreuztabelle'; break; } 
            case 'showreport': { $title[] = 'spielberichte'; break; }                                         
            case 'showteaminfo': { $title[] = 'mannschaften'; break; } 
            case 'showclubinfo': { $title[] = 'vereine'; break; } 
            case 'showplayers': { $title[] = 'mannschaftskader'; break; }  
            case 'showplayer':{ $title[] = 'spieler'; break; }
            case 'showtiprules': { $title[] = 'tippspiel/regeln'; break; }   
            case 'showstats': { $title[] = 'statistik'; break; }  
            case 'showuser': { $title[] = 'benutzer'; break; } 
            case 'showplayground': { $title[] = 'spielorte'; break; } 
            case 'eventsstats': { $title[] = 'ereignisse'; break; }                                        
            unset($vars['func']);              
        }
        
        // Load round
        if (isset($r)) {
            $query = "SELECT `name` FROM `#__joomleague_rounds` WHERE `matchcode` = $r";
            $database->setQuery($query);
            $roundName = $database->loadResult(); }
        if (!empty($roundName)) { $title[] = $roundName; unset($vars['r']); }
        // Round END

        // Load club
        if (isset($cid)) { $query = "SELECT `name`	FROM `#__joomleague_clubs` WHERE `id` = $cid";
            $database->setQuery($query);
            $clubName = $database->loadResult(); }
        if (!empty($clubName)) { $title[] = $clubName; unset($vars['cid']); }
        // Load club END

        // Load team
        if (isset($tid)) { $query = "SELECT `name` FROM `#__joomleague_teams`	WHERE `id` = $tid";
            $database->setQuery($query);
            $teamName = $database->loadResult(); }
        if (!empty($teamName)) { $title[] = $teamName; unset($vars['tid']); }
        // Load team END

        // Load team joomleague
        if (isset($ttid)) { $query = "SELECT `team_id` FROM `#__joomleague_team_joomleague`	WHERE `id` = $ttid";
            $database->setQuery($query);
            $teamJoomleagueID = $database->loadResult();
            $query = "SELECT `name`	FROM `#__joomleague_teams` WHERE `id` = $teamJoomleagueID";
            $database->setQuery($query);
            $teamJoomleagueName = $database->loadResult(); }
        if (!empty($teamJoomleagueName)) { $title[] = $teamJoomleagueName; unset($vars['ttid']); }
        // Load team END

        // Load mode
        //switch ($mode)
        //{
//            case 'all':
//                { $title[] = 'gesamt'; break;}
//        unset($vars['mode']);
//        }
        // Load mode END

        // Load user (Tipp Overview)
        if (isset($u)) { $query = "SELECT `username` FROM `#__users`	WHERE `id` = $u";
            $database->setQuery($query);
            $userName = $database->loadResult(); }
        if (!empty($userName)) { $title[] = $userName; unset($vars['u']); }
        // Load user (Tipp Overview) END
        
        // Load user (Profile)
        if (isset($uid)) { $query = "SELECT `username` FROM `#__users`	WHERE `id` = $uid";
            $database->setQuery($query);
            $userName = $database->loadResult(); }
        if (!empty($userName)) { $title[] = $userName; unset($vars['uid']); }
        // Load user (Profile) END
        
        // Load playground
        if (isset($pgid)) { $query = "SELECT `name`	FROM `#__joomleague_playgrounds` WHERE `id` = $pgid";
            $database->setQuery($query);
            $playgroundName = $database->loadResult(); }
        if (!empty($playgroundName)) { $title[] = $playgroundName; unset($vars['pgid']); }

        // Load match id
        if (isset($mid)) {
            $database->setQuery(sprintf("SELECT t.name AS name
                                         FROM #__joomleague_matches m
                                         LEFT JOIN #__joomleague_teams t on m.matchpart1 = t.id
                                         WHERE m.match_id = %s", $mid));    
            $matchName1 = $database->loadResult();
            $database->setQuery(sprintf("SELECT t.name AS name
                                         FROM #__joomleague_matches m
                                         LEFT JOIN #__joomleague_teams t on m.matchpart2 = t.id
                                         WHERE m.match_id = %s", $mid));    
            $matchName2 = $database->loadResult();                                         
            $matchName = $matchName1.' vs. '.$matchName2; }
        if (!empty($matchName)) { $title[] = $matchName; unset($vars['mid']);}

        // Load player id
        if (isset($pid)) {
            $database->setQuery(sprintf("SELECT `player_id`	FROM `#__joomleague_playertool` WHERE `id` = %s", $pid));
            $playerid = $database->loadResult();        
            $database->setQuery(sprintf("SELECT `firstname`	FROM `#__joomleague_players` WHERE `id` = %s", $playerid));
            $firstname = $database->loadResult(); 
            $database->setQuery(sprintf("SELECT `lastname`	FROM `#__joomleague_players` WHERE `id` = %s", $playerid));
            $lastname = $database->loadResult(); 
            $playername = $firstname.' '.$lastname;
            }
        if (!empty($playername)) { $title[] = $playername; unset($vars['pid']); }

        // Load event id
        if (isset($evid)) { $query = "SELECT `name`	FROM `#__joomleague_eventtypes` WHERE `id` = $evid";
            $database->setQuery($query);
            $eventName = $database->loadResult(); }
        if (!empty($eventName)) { $title[] = $eventName; unset($vars['evid']); }
        
        $title[] = $task.$bid;

        if (count($title) > 0) $string = sef_404::sefGetLocation($string, $title, @$this_task, null, null, @$vars['lang']);
        if ($debug) { $GLOBALS['JOOMSEF_DEBUG']['CLASS_SEF_404'][$debug_string]['STRING'] = $string; }
        
        return $string;
    }
}
?>
